<template>
</template>

<script>
import store from '../utils/store'
import * as auth from '../api/auth'
import * as user from '../api/user'
export default {
  name: 'auth',
  mounted () {
    // store.commit('setToken', '507f2d9db13ab738209187c70eea2a4f')
    this.auth()
  },
  methods: {
    auth () {
      let that = this
      // store.commit('setToken', "507f2d9db13ab738209187c70eea2a4f")
      if (that.$route.query.code) {
        auth.getUser(that.$route.query.code, store.getters.referId).then(res => {
          if (res.code !== 200) {
            return
          }
          this.getInfo()
          res = res.data
          if (res.token !== '') {
            store.commit('setToken', res.token)
          }
          if (res.needBind === true) {
            window.location.href = '/binding'
            // that.$router.push({path: '/binding'})
          } else {
            window.location.href = '/home'
            // that.$router.push({path: '/home'})
          }
        })
      } else {
        // window.location.href = process.env.BASE_API + '/auth/code'

        window.location.href = process.env.BASE_API + '/auth/code?redirect-url=http://www.niceleads.cn/auth'
        // window.location.href = process.env.BASE_API + '/auth/code?redirect-url=http://localhost:1024/auth'
      }
    },
    getInfo () {
      user.userInfo().then(user => {
        store.commit('setUserInfo', user.data)
      })
    }
  }
}
</script>

<style scoped>

</style>
